import React, { Component } from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'
import { adminRoutes } from './routes'
import Frame from './component/Frame'
import './App.css'
import { getToken, isLogin } from './utils/auth'

export default class App extends Component {
  render() {
    console.log('是否登录', isLogin(), getToken())
    return isLogin() ? (
      <Frame>
        <Switch>
          {
            adminRoutes.map(route => {

              return <Route
                key={route.path}
                path={route.path}
                exact={route.exact}
                render={routeProps => {
                  return <route.component {...routeProps} />
                }} />
            })
          }
          <Redirect to={adminRoutes[0].path} from='/admin' />
          <Redirect to="/404" />
        </Switch>
      </Frame>
    ) : (<Redirect to='/login' />)
  }
}
